//
//  SignInViewController.m
//  MobileOffice
//
//  Created by jjkj on 16/10/25.
//  Copyright © 2016年 liaoningjujin. All rights reserved.
//

#import "SignInViewController.h"
#import "BasicModel.h"
#import "SignInButton.h"
#import "UserHeadImageModel.h"
#import <CoreLocation/CoreLocation.h>
#import "ImageDetailViewController.h"
#import <SystemConfiguration/CaptiveNetwork.h>
#import <BaiduMapAPI_Location/BMKLocationComponent.h>
#import <BaiduMapAPI_Search/BMKGeocodeSearch.h>
#import <BaiduMapAPI_Map/BMKPointAnnotation.h>
#import "MacAddressModel.h"
#import "SignOutInfoModel.h"
#import "MapDetailViewController.h"
#import "SignInNoticeModel.h"
#import <AssetsLibrary/AssetsLibrary.h>
#import "LocationListModel.h"
#import "SigninAddressMapViewController.h"

#define uploadPicInfo @"uploadPicInfo"//上传图片
#define GetWifiMac @"GetWifiMac"//获取mac地址
#define getServiceTime @"getServiceTime"//请求服务器时间
#define UpdateCardInfo @"UpdateCardInfo"//更新考勤打卡记录
#define postSignInOutInfo @"postSignInOutInfo"//提交NFC/拍照考勤信息
#define getMonthAttendanceList @"getMonthAttendanceList"//考勤记录
#define getSigninLocationList @"getSigninLocationList"//获取百度地图可签到位置区域

@interface SignInViewController ()<UIScrollViewDelegate,UIImagePickerControllerDelegate,UINavigationControllerDelegate,BMKLocationServiceDelegate,BMKGeoCodeSearchDelegate>
{
    NSMutableArray *_buttonArr;//保存签到button
    UIScrollView *_scrollView;//滚动视图
    UILabel *_dateLabel;//时间label
    NSString *_dateStr;//服务器时间
    NSTimer *_timer;//定时器
    //UIImage *_image;//所拍的图片
    NSMutableArray *_photoArr;//所拍照片的arr
    NSMutableArray *_photoButtonArr;//签退照片Buton
    UserHeadImageModel *_imageModel;//照片model
    MacAddressModel *_macAddressModel;//可签到macAddress model
    NSString *_mapAddress;//当前位置信息
    NSString *_signIntype;//0：签到按钮点击退  1：签到按钮点击签到
    BMKUserLocation *_userLocation;//保存当前用户的定位信息
    BOOL _isCompanyWifi;//是否是可签到wifi
    UIView *_noticeView;//考勤记录提示框
    LocationListModel *_locationModel;
}
//@property (nonatomic,strong) CLLocationManager *locationManager;
@property (nonatomic,strong) BMKLocationService *locService;
@property (nonatomic,strong) BMKGeoCodeSearch  *geocodesearch;
@property (nonatomic,strong) NSString *outOfArea;//是否在可签到范围内
@property (nonatomic,strong) NSString *placeX;//纬度
@property (nonatomic,strong) NSString *placeY;//经度
@end

@implementation SignInViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setNavigationTitle:_titleStr];
    if ([_titleStr isEqualToString:@"签到"]) {
        _signIntype=@"1";
    }else{
        _signIntype=@"0";
    }
    [self setLeftBackNavigation];
    [self setRightBackNavigation];
    [self getSigninLocationListRequest];
    [self creatView];
    //[self serverDateRequest];
    // Do any additional setup after loading the view.
}

#pragma mark - creatView

- (void)creatView{
    UIView *dateView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, IPHONE_WIDTH, 120)];
    dateView.backgroundColor=COLOR_MIDBLUE;
    [self.view addSubview:dateView];
    
    _dateLabel=[MyControl creatLabelWithFrame:CGRectMake(10, 15, IPHONE_WIDTH-20, 50) text:@""];
    _dateLabel.textAlignment=NSTextAlignmentCenter;
    _dateLabel.font=[UIFont systemFontOfSize:17 weight:2];
    _dateLabel.textColor=[UIColor whiteColor];
    [dateView addSubview:_dateLabel];
    
    _buttonArr=[[NSMutableArray alloc]init];
    //设置签到按钮
    NSArray *titleArr=@[@"拍照",@"NFC",@"二维码",@"WIFI"];
    
    for (int i=0; i<titleArr.count; i++) {
        SignInButton *button=[[SignInButton alloc]initWithFrame:CGRectMake(IPHONE_WIDTH/titleArr.count*i, dateView.height-40, IPHONE_WIDTH/titleArr.count, 40)];
        button.tag=100+i;
        button.textLabel.text=titleArr[i];
//        [button setTitle:titleArr[i] forState:UIControlStateNormal];
//        [button setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
//        button.titleLabel.font=FONT_14;
//        [button setTitleColor:COLOR_MIDBLUE forState:UIControlStateSelected];
        [button addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
        [dateView addSubview:button];
        //默认选中第一个按钮
        if (i==0) {
            button.selected=YES;
            //[button setColor:BACKCOLOR_BLUE];
            [self buttonClick:button];
        }
        [_buttonArr addObject:button];
    }


    _scrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0, dateView.y+dateView.height, IPHONE_WIDTH, IPHONE_HEIGHT-(dateView.y+dateView.height)-64)];
    _scrollView.pagingEnabled=YES;
    _scrollView.bounces=NO;
    _scrollView.delegate=self;
    _scrollView.tag=130;
    _scrollView.scrollEnabled=NO;
    _scrollView.showsVerticalScrollIndicator=NO;
    _scrollView.showsHorizontalScrollIndicator=NO;
    _scrollView.contentSize=CGSizeMake(IPHONE_WIDTH*titleArr.count, 0);
    [self.view addSubview:_scrollView];
    [self getDateStrWithNow];
    [self creatPhotoView];
    [self creatNFCView];
    [self creatWIFIView];
}

- (void)backClick{
    
    //关掉计数器
    if ([_timer isValid]) {
        [_timer invalidate];
        _timer=nil;
    }
    [super backClick];
}

#pragma mark -creatPhotoView
- (void)creatPhotoView{
    _photoArr=[NSMutableArray new];
    _photoButtonArr=[NSMutableArray new];
    //签到
    UILabel *signInLabel=[MyControl creatLabelWithFrame:CGRectMake(10, 10, IPHONE_WIDTH-20, 20) text:[NSString stringWithFormat:@"%@图片：",_titleStr]];
    [_scrollView addSubview:signInLabel];
    
    //添加图片
    CGFloat buttonWidth=(IPHONE_WIDTH-80*3)/4;//button间隔
    for (int i=0; i<7; i++) {
        UIButton *signButton=[MyControl creatButtonWithFrame:CGRectMake(buttonWidth*(i%3+1)+80*(i%3), signInLabel.y+signInLabel.height+buttonWidth*(i/3+1)+80*(i/3), 80, 80) target:self sel:@selector(addPhoto:) tag:140+i image:@"AlbumAddBtn@2x" title:nil];
        if (i!=0) {
            signButton.hidden=YES;
        }
        [_scrollView addSubview:signButton];
        [_photoButtonArr addObject:signButton];
    }
    
    UIImageView *mapImageView=[MyControl creatImageViewWithFrame:CGRectMake(15, _scrollView.height-55-43, 30, 30) imageName:@"k_dingwei@2x"];
    [_scrollView addSubview:mapImageView];
    
    //地图位置button
    UIButton *mapButton=[MyControl creatButtonWithFrame:CGRectMake(mapImageView.x+mapImageView.width+8, mapImageView.y, IPHONE_WIDTH-(mapImageView.x+mapImageView.width+8)-8, 30) target:self sel:@selector(mapButtonClick) tag:170 image:nil title:@"正在获取位置信息..."];
    [mapButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
    mapButton.userInteractionEnabled=NO;
    mapButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    //mapButton.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
    [_scrollView addSubview:mapButton];
    
    //拍照提交按钮
    UIButton *subBtn=[MyControl creatButtonWithFrame:CGRectMake(15, _scrollView.height-55, IPHONE_WIDTH-30, 40) target:self sel:@selector(submitClick:) tag:150 image:nil title:@"提交"];
    subBtn.backgroundColor=COLOR_MIDBLUE;
    subBtn.layer.cornerRadius=5;
    [subBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [_scrollView addSubview:subBtn];
    
    _geocodesearch = [[BMKGeoCodeSearch alloc] init];
    //编码服务的初始化(就是获取经纬度,或者获取地理位置服务)
    _geocodesearch.delegate = self;//设置代理为self
    
    _locService = [[BMKLocationService alloc]init];//定位功能的初始化
    _locService.delegate = self;//设置代理位self
    _locService.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;
    //启动LocationService
    [_locService startUserLocationService];//启动定位服务
    
    //[self onClickReverseGeocode];
    
    
    
//    self.locationManager = [[CLLocationManager alloc] init];
//
//    self.locationManager.delegate = self;
//    
//    // 设置定位精度
//    // kCLLocationAccuracyNearestTenMeters:精度10米
//    // kCLLocationAccuracyHundredMeters:精度100 米
//    // kCLLocationAccuracyKilometer:精度1000 米
//    // kCLLocationAccuracyThreeKilometers:精度3000米
//    // kCLLocationAccuracyBest:设备使用电池供电时候最高的精度
//    // kCLLocationAccuracyBestForNavigation:导航情况下最高精度，一般要有外接电源时才能使用
//    self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
//    [_locationManager requestAlwaysAuthorization];//添加这句
//
//    // distanceFilter是距离过滤器，为了减少对定位装置的轮询次数，位置的改变不会每次都去通知委托，而是在移动了足够的距离时才通知委托程序
//    // 它的单位是米，这里设置为至少移动1000再通知委托处理更新;
//    self.locationManager.distanceFilter = 1000.0f; // 如果设为kCLDistanceFilterNone，则每秒更新一次;
//    
//    if ([CLLocationManager locationServicesEnabled]) {
//        // 启动位置更新
//        // 开启位置更新需要与服务器进行轮询所以会比较耗电，在不需要时用stopUpdatingLocation方法关闭;
//        [self.locationManager startUpdatingLocation];
//    }
//    else {
//        [LZXHelper postMessageWithText:@"请开启定位功能！" View:self.view];
//    }

}


#pragma mark -creatNFCView
- (void)creatNFCView{
    [self addReminderViewWithFrame:CGRectMake(IPHONE_WIDTH, 50, IPHONE_WIDTH, 21) msg:@"请将NFC设备贴近手机" backView:_scrollView];
}

#pragma mark -creatWIFIView
- (void)creatWIFIView{
    //Wifi
    UIImageView *wifiImageView=[MyControl creatImageViewWithFrame:CGRectMake(IPHONE_WIDTH*3+(IPHONE_WIDTH-110)/2, (_scrollView.height-90-110)/2, 110, 110) imageName:@"k_ic_wifi@2x.jpg"];
    [_scrollView addSubview:wifiImageView];
    
    //地图图标
    UIImageView *mapImageView=[MyControl creatImageViewWithFrame:CGRectMake(IPHONE_WIDTH*3+15, _scrollView.height-43, 30, 30) imageName:@"k_dingwei@2x"];
    [_scrollView addSubview:mapImageView];
    
    //地图位置button
    UIButton *mapButton=[MyControl creatButtonWithFrame:CGRectMake(mapImageView.x+mapImageView.width+8, mapImageView.y, IPHONE_WIDTH-(15+mapImageView.width+8)-8, 30) target:self sel:@selector(mapButtonClick) tag:171 image:nil title:@"正在获取位置信息..."];
    mapButton.userInteractionEnabled=NO;
    [mapButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
    mapButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    //mapButton.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
    [_scrollView addSubview:mapButton];
    
//    //WIFI提交按钮
//    UIButton *subBtn2=[MyControl creatButtonWithFrame:CGRectMake(IPHONE_WIDTH*3+15, _scrollView.height-55, IPHONE_WIDTH-30, 40) target:self sel:@selector(submitClick:) tag:153 image:nil title:@"提交"];
//    subBtn2.backgroundColor=COLOR_MIDBLUE;
//    subBtn2.layer.cornerRadius=5;
//    subBtn2.hidden=YES;
//    [subBtn2 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
//    [_scrollView addSubview:subBtn2];
}

#pragma mark -考勤记录提示框
//- (void)creatNoticeView
- (void)creatNoticeViewWithModel:(SignInNoticeModel *)model message:(NSString *)msg{
    if (_noticeView) {
        return;
    }
    _noticeView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, IPHONE_WIDTH, IPHONE_HEIGHT)];
    [[[UIApplication sharedApplication].delegate window]addSubview:_noticeView];
    
    [LZXHelper postMessageWithText:msg View:[[UIApplication sharedApplication].delegate window]];
    //半透明框
    UIView *backView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, IPHONE_WIDTH, IPHONE_HEIGHT)];
    backView.backgroundColor=[UIColor blackColor];
    backView.alpha=0.4;
    [_noticeView addSubview:backView];
    
    //白色背景
    UIView *whiteView=[[UIView alloc]initWithFrame:CGRectMake(15, (IPHONE_HEIGHT-300)/2, IPHONE_WIDTH-30, 290)];
    whiteView.backgroundColor=[UIColor whiteColor];
    whiteView.layer.masksToBounds=YES;
    whiteView.layer.cornerRadius=10;
    [_noticeView addSubview:whiteView];
    
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    
    [formatter setDateFormat:@"yyyy-MM"];
    NSString *timestamp = [formatter stringFromDate:[NSDate date]];
    //考勤记录title
    UILabel *titleLabel=[MyControl creatLabelWithFrame:CGRectMake(15, 15, whiteView.width-30, 20) text:[NSString stringWithFormat:@"%@%@月考勤记录",[LZXHelper getUserName],timestamp]];
    titleLabel.textAlignment=NSTextAlignmentCenter;
    titleLabel.font=[UIFont systemFontOfSize:18];
    [whiteView addSubview:titleLabel];
    //添加下划线
    UILabel *line=[[UILabel alloc]initWithFrame:CGRectMake(titleLabel.x, titleLabel.y+titleLabel.height+15, titleLabel.width, 1)];
    line.backgroundColor=BACKCOLOR_GRAY;
    [whiteView addSubview:line];
    
    //签到信息
    CGFloat labelWidth=(whiteView.width-30)/2;
//    SignInNoticeModel *noticeModel=nil;
//    if (model.dataArr.count>0) {
//        noticeModel=model.dataArr[0];
//    }
    for (int i=0; i<6; i++) {
        UILabel *noticeLabel=[MyControl creatLabelWithFrame:CGRectMake(15+i%2*labelWidth, line.y+line.height+15*(i/2+1)+i/2*20, labelWidth, 20) text:@""];
        if (i%2!=0) {
            noticeLabel.textAlignment=NSTextAlignmentRight;
        }
        [whiteView addSubview:noticeLabel];
        switch (i) {
            case 0:
            {
                noticeLabel.text=[NSString stringWithFormat:@"应到：%.1f天",[model.oughtToDays floatValue]];
            }
                break;
            case 1:
            {
                noticeLabel.text=[NSString stringWithFormat:@"实到：%.1f天",[model.realDays floatValue]];
            }
                break;
            case 2:
            {
                noticeLabel.text=[NSString stringWithFormat:@"未签到：%@次",model.unSingTimes];
            }
                break;
            case 3:
            {
                noticeLabel.text=[NSString stringWithFormat:@"旷工：%@",[self getDateStrWithTimeStr:[model.leaveWorkDays intValue]]];
            }
                break;
            case 4:
            {
                noticeLabel.text=[NSString stringWithFormat:@"迟到：%.1f分钟",[model.lateMinutes floatValue]];
            }
                break;
            case 5:
            {
                noticeLabel.text=[NSString stringWithFormat:@"迟到：%@次",model.lateTimes];
            }
                break;
            default:
                break;
        }
        
        if (i==5) {
            //添加下划线
            UILabel *line2=[[UILabel alloc]initWithFrame:CGRectMake(titleLabel.x, noticeLabel.y+noticeLabel.height+15, titleLabel.width, 1)];
            line2.backgroundColor=BACKCOLOR_GRAY;
            [whiteView addSubview:line2];
            
            //事假
            UILabel *leftLabel=[MyControl creatLabelWithFrame:CGRectMake(15, line2.y+line2.height+15, labelWidth, 20) text:[NSString stringWithFormat:@"事假：%.1f小时",[model.absenceVacate floatValue]]];

            [whiteView addSubview:leftLabel];
            
            //病假
            UILabel *rightLabel=[MyControl creatLabelWithFrame:CGRectMake(leftLabel.x+leftLabel.width,leftLabel.y, labelWidth, 20) text:[NSString stringWithFormat:@"病假：%.1f小时",[model.sickVacate floatValue]]];
            rightLabel.textAlignment=NSTextAlignmentRight;
            [whiteView addSubview:rightLabel];
            
            //添加下划线
            UILabel *line3=[[UILabel alloc]initWithFrame:CGRectMake(titleLabel.x, rightLabel.y+rightLabel.height+15, titleLabel.width, 1)];
            line3.backgroundColor=BACKCOLOR_GRAY;
            [whiteView addSubview:line3];
        }
    }
    
    //确认按钮
    UIButton *knowBtn=[MyControl creatButtonWithFrame:CGRectMake(whiteView.width-100-10, whiteView.height-40-15, 100, 40) target:self sel:@selector(knowClick) tag:190 image:nil title:@"我知道了"];
    knowBtn.backgroundColor=COLOR_MIDBLUE;
    [knowBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    knowBtn.layer.cornerRadius=5;
    [whiteView addSubview:knowBtn];
}

- (NSString *)getDateStrWithTimeStr:(int)time{
    if (time/60<24&&(time/60)>=1) {
        return [NSString stringWithFormat:@"%.1f小时",time/60.0];
    }else if(time/60<1){
        return [NSString stringWithFormat:@"%.1f分钟",(float)time];
    }else{
        return [NSString stringWithFormat:@"%.1f天",time/(60.0*24)];
    }
}

- (void)setOutOfAreaWithListModel{
    if (_userLocation) {
        CGFloat latitude=_userLocation.location.coordinate.latitude;
        CGFloat longitude=_userLocation.location.coordinate.longitude;
        NSString *latitudeStr=[NSString stringWithFormat:@"%.4f",latitude];
        NSString *longitudeStr=[NSString stringWithFormat:@"%.4f",longitude];
        CGFloat minPoint=10000;
        //先取出离的最近的距离
        for (LocationListModel *locationModel in _locationModel.dataArr) {
            //第一个坐标
            
            CLLocation *current=[[CLLocation alloc] initWithLatitude:latitudeStr.floatValue longitude:longitudeStr.floatValue];
            
            //第二个坐标
            
            CLLocation *before=[[CLLocation alloc] initWithLatitude:locationModel.latitude.floatValue longitude:locationModel.longitude.floatValue];
            
            // 计算距离
            
            CLLocationDistance meters=[current distanceFromLocation:before];
            //取出最小值
            if (minPoint>meters) {
                minPoint=meters;
            }
            //与可签到半径判断
            if (minPoint<locationModel.radius.floatValue) {
                self.outOfArea=@"0";
                self.placeX=[NSString stringWithFormat:@"%f",locationModel.latitude.floatValue];
                self.placeY=[NSString stringWithFormat:@"%f",locationModel.longitude.floatValue];
                break;
            }
        }
    }
}

//处理位置坐标更新
- (void)didUpdateBMKUserLocation:(BMKUserLocation *)userLocation
{
    NSLog(@"didUpdateUserLocation lat %f,long %f",userLocation.location.coordinate.latitude,userLocation.location.coordinate.longitude);
    _userLocation=userLocation;
    //先获取到位置再调用接口
    if (_locationModel) {
        [self setOutOfAreaWithListModel];
    }else{
        [self getSigninLocationListRequest];
    }

    //普通态
//    //以下_mapView为BMKMapView对象
//    [_mapView updateLocationData:userLocation]; //更新地图上的位置
//    _mapView.centerCoordinate = userLocation.location.coordinate; //更新当前位置到地图中间
    //地理反编码
    BMKReverseGeoCodeOption *reverseGeocodeSearchOption = [[BMKReverseGeoCodeOption alloc]init];
    reverseGeocodeSearchOption.reverseGeoPoint = userLocation.location.coordinate;
    BOOL flag = [_geocodesearch reverseGeoCode:reverseGeocodeSearchOption];
    if(flag){
        NSLog(@"反geo检索发送成功");
        [_locService stopUserLocationService];
    }else{
        NSLog(@"反geo检索发送失败");
    }
}

#pragma mark -------------地理反编码的delegate---------------
-(void)onGetReverseGeoCodeResult:(BMKGeoCodeSearch *)searcher result:(BMKReverseGeoCodeResult *)result errorCode:(BMKSearchErrorCode)error
{
    NSLog(@"address:%@----%@",result.addressDetail,result.address);
    //addressDetail:     层次化地址信息
    //address:    地址名称
    //businessCircle:  商圈名称
    // location:  地址坐标
    //  poiList:   地址周边POI信息，成员类型为BMKPoiInfo
    if (error == 0) {
//        BMKPointAnnotation* item = [[BMKPointAnnotation alloc]init];
//        item.coordinate = result.location;
//        item.title = result.address;
        //拍照的button
        _mapAddress=[result.address copy];
        UIButton *mapButton=(UIButton *)[_scrollView viewWithTag:170];
        mapButton.userInteractionEnabled=YES;
        [mapButton setTitle:result.address forState:UIControlStateNormal];
        //wifi的button
        UIButton *mapButton2=(UIButton *)[_scrollView viewWithTag:171];
        mapButton2.userInteractionEnabled=YES;
        [mapButton2 setTitle:result.address forState:UIControlStateNormal];
    }
}


//#pragma mark - CLLocationManagerDelegate
//// 地理位置发生改变时触发
//- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
//{
//    // 获取经纬度
//    NSLog(@"纬度:%f",newLocation.coordinate.latitude);
//    NSLog(@"经度:%f",newLocation.coordinate.longitude);
//    // 停止位置更新
//    [manager stopUpdatingLocation];
//
//
//}
////获取经纬度和详细地址
//- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray<CLLocation *> *)locations{
//    CLLocation *location = [locations lastObject];
//    //反向地理编码
//    CLGeocoder *clGeoCoder = [[CLGeocoder alloc] init];
//    CLLocation *cl = [[CLLocation alloc] initWithLatitude:location.coordinate.latitude longitude:location.coordinate.longitude];
//    [clGeoCoder reverseGeocodeLocation:cl completionHandler: ^(NSArray *placemarks,NSError *error) {
//        for (CLPlacemark *placeMark in placemarks) {
//            NSDictionary *addressDic = placeMark.addressDictionary;
//            
//            NSString *state=[addressDic objectForKey:@"State"];
//            NSString *city=[addressDic objectForKey:@"City"];
//            
//            NSString *subLocality=[addressDic objectForKey:@"SubLocality"];
//            
//            NSString *street=[addressDic objectForKey:@"Street"];
//            
//            NSLog(@"所在城市====%@ %@ %@ %@", state, city, subLocality, street);
//            [_locationManager stopUpdatingLocation];
//            
//        }
//        
//    }];
//}
//
//// 定位失误时触发
//- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
//{
//    NSLog(@"error:%@",error);
//}

#pragma mark- 获取mac地址
- (NSString *)getSSIDInfo

{
    
    NSArray *ifs = (__bridge_transfer NSArray *)CNCopySupportedInterfaces();
    
    NSDictionary *info = nil;
    
    for (NSString *ifnam in ifs) {
        
        info = (__bridge_transfer NSDictionary *)CNCopyCurrentNetworkInfo((__bridge CFStringRef)ifnam);
        
        if (info && [info count]) {
            
            break;
        }
    }
    
    return info[@"BSSID"];
    
}


#pragma mark -地图坐标点击事件
- (void)mapButtonClick{
    SigninAddressMapViewController *map=[SigninAddressMapViewController new];
    map.addressX=self.placeX;
    map.addressY=self.placeY;
    [self.navigationController pushViewController:map animated:YES];
}

#pragma mark - 拍照按钮点击

- (void)addPhoto:(UIButton *)button{
    //最后一张图片为添加按钮对其进行特殊处理
    if (button.tag-140==_photoArr.count) {
        if (![UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]) {
            [LZXHelper postMessageWithText:@"您的手机还不支持照相功能！" View:self.view];
            return;
        }
        if (_photoArr.count>=3) {
            [LZXHelper postMessageWithText:@"最多只能提交3张照片！" View:self.view];
            return;
        }
        
        UIImagePickerController *imagePickerController=[[UIImagePickerController alloc]init];
        imagePickerController.sourceType=UIImagePickerControllerSourceTypeCamera;
        imagePickerController.delegate=self;
        imagePickerController.allowsEditing=YES;
        [self presentViewController:imagePickerController animated:NO completion:nil];
    }else{
        ImageDetailViewController *imageViewController=[ImageDetailViewController new];
        imageViewController.image=_photoArr[button.tag-140];
        [self.navigationController pushViewController:imageViewController animated:YES];
    }

}

#pragma mark -签到选择模块点击

- (void)buttonClick:(UIButton *)button{
    if (button.tag==102) {
        [LZXHelper postMessageWithText:@"对不起，二维码还未开通" View:self.view];
        return;
    }else if (button.tag==103){
        [self macAddressRequest];
    }
    [self changeButton:button];
    //[UIView animateWithDuration:0.3 animations:^{
        _scrollView.contentOffset=CGPointMake((button.tag-100)*IPHONE_WIDTH, 0);
    //}];
}

- (void)changeButton:(UIButton *)selectButton{
    //if (!button.selected) {
    for (int i=0; i<_buttonArr.count; i++) {
        UIButton *button=_buttonArr[i];
        if (selectButton.tag==button.tag) {
            button.selected=YES;
            //[button setColor:BACKCOLOR_GREEN];
        }else{
            button.selected=NO;
            //[button setColor:BACKCOLOR_GREEN];
        }
    }
    
}

#pragma mark -提示框点击

- (void)knowClick{
    if (_noticeView) {
        [_noticeView removeFromSuperview];
        _noticeView=nil;
        NSDictionary *dict=@{@"userInfo":@"更新打卡数据成功！"};
        [[NSNotificationCenter defaultCenter]postNotificationName:@"signOutSuccess" object:nil userInfo:dict];
        [self backClick];
    }
}

#pragma mark -提交按钮点击事件
- (void)submitClick:(UIButton *)button{
    if (!_mapAddress) {
        [LZXHelper postMessageWithText:@"没有获取到位置信息不能提交！" View:self.view];
        return;
    }
    NSString *cancelButtonTitle = NSLocalizedString(@"取消", nil);
    NSString *otherButtonTitle = NSLocalizedString(@"确定", nil);
    if (button.tag==150) {
        if (_photoArr.count==0) {
            [LZXHelper postMessageWithText:@"请先拍照！" View:self.view];
            return;
        }
        //        NSString *otherButtonTitle2 = NSLocalizedString(@"拍照", nil); 不支持拍照

        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:[NSString stringWithFormat:@"确认要进行%@操作?",_titleStr] message:nil preferredStyle:UIAlertControllerStyleAlert];
        
        // Create the actions.
        UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:cancelButtonTitle style:UIAlertActionStyleCancel handler:^(UIAlertAction *action)
                                       {
                                           //cancel Button
                                       }];
        UIAlertAction *otherAction = [UIAlertAction actionWithTitle:otherButtonTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction *action)
                                      {
                                          NSThread* myThread = [[NSThread alloc] initWithTarget:self
                                                                                       selector:@selector(uploadPhotoImage)
                                                                                         object:nil];
                                          [myThread start];
                                      }];
        
        
        // Add the actions.
        [alertController addAction:otherAction];
        
        [alertController addAction:cancelAction];
        
        [self presentViewController:alertController animated:YES completion:nil];
    }else if(button.tag==153){
        if (_isCompanyWifi) {
            //        NSString *otherButtonTitle2 = NSLocalizedString(@"拍照", nil); 不支持拍照
            
//            UIAlertController *alertController = [UIAlertController alertControllerWithTitle:[NSString stringWithFormat:@"确认要进行%@操作?",_titleStr] message:nil preferredStyle:UIAlertControllerStyleAlert];
//            
//            // Create the actions.
//            UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:cancelButtonTitle style:UIAlertActionStyleCancel handler:^(UIAlertAction *action)
//                                           {
//                                               //cancel Button
//                                           }];
//            UIAlertAction *otherAction = [UIAlertAction actionWithTitle:otherButtonTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction *action)
//                                          {
//                                              [self postSignInOutInfoRequest];
//                                          }];
//            
//            
//            // Add the actions.
//            [alertController addAction:otherAction];
//
//            [alertController addAction:cancelAction];
//            
//            [self presentViewController:alertController animated:YES completion:nil];
        }
    }
}

#pragma mark -相册Delegate

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
    //编辑时调用
    if (!info[@"UIImagePickerControllerEditedImage"])
    {
        return;
    }
    UIImage *image=info[@"UIImagePickerControllerEditedImage"];
    [_photoArr insertObject:image atIndex:0];
    //将拍的图片显示出来
    for (int i=0;i<_photoButtonArr.count;i++) {
        UIButton *photo=_photoButtonArr[i];
        if (i<_photoArr.count) {
            UIImage *image=_photoArr[i];
            [photo setImage:image forState:UIControlStateNormal];
            photo.hidden=NO;
        }else{
            photo.hidden=YES;
        }
        if (i==_photoArr.count) {
            //[photo setImage:[UIImage imageNamed:@"AlbumAddBtn@2x"] forState:UIControlStateNormal];
            photo.hidden=NO;
        }
    }

//    __block NSString* imageFileName;
//
//
//    NSURL *imageURL = [info valueForKey:UIImagePickerControllerReferenceURL];
//
//    ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset)
//
//    {
//
//        ALAssetRepresentation *representation = [myasset defaultRepresentation];
//
//        imageFileName = [representation filename];
//
//    };
//      ALAssetsLibrary* assetslibrary = [[ALAssetsLibrary alloc] init];
//    [assetslibrary assetForURL:imageURL
//                   resultBlock:resultblock
//                  failureBlock:nil];
//    NSArray *imagePath = [imageFileName componentsSeparatedByString:@"."];
//    [NSThread detachNewThreadSelector:@selector(uploadPhotoImage) toTarget:self withObject:nil];

    [picker dismissViewControllerAnimated:YES completion:nil];
}



#pragma mark -scrollerDelegate

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    if (scrollView.tag==130) {
        NSInteger num=scrollView.contentOffset.x/IPHONE_WIDTH;
        UIButton *button=_buttonArr[num];
        [self changeButton:button];
    }
}


#pragma mark -获取当前时间
- (void)getDateStrWithNow{
//    if (!_dateStr) {
//        return ;
//    }
//    NSDateFormatter *formatter=[[NSDateFormatter alloc]init];
//    [formatter setDateFormat:@"yyyy-MM-dd \n HH:mm:ss"];
//    NSDate *serverDate=[formatter dateFromString:_dateStr];
//    
//    NSInteger time=[NSDate dateWithTimeIntervalSince1970:<#(NSTimeInterval)#>]
    
    _timer = [NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(timerFunc) userInfo:nil repeats:YES];
    
}
#pragma mark -定时器刷新函数
- (void)timerFunc

{
#warning 由于时间问题  这里采用的是系统时间 后续需改为服务器时间
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    
    [formatter setDateFormat:@"yyyy-MM-dd \n HH:mm:ss"];
    
    NSString *timestamp = [formatter stringFromDate:[NSDate date]];
    
    _dateLabel.text=timestamp;//时间在变化的语句
    
    //NSLog(@"%@",timestamp);
    
}

#pragma mark -获取当前时间请求

- (void)serverDateRequest{
    [LZXHelper postLoadViewWithText:HUD_PLEASEWAIT View:self.view];
    
    NSString* soap = [NSString stringWithFormat:@"<sessionId>%@</sessionId>\n<content></content>",[LZXHelper getSessionID]];
    // __weak AddressBookViewController *mySelf=self;
    [HttpRequest SOAPData:[LZXHelper getServerURL] SoapMthod:getServiceTime soapBody:soap success:^(id responseObject) {
        [LZXHelper hideLoadViewWithView:self.view];
        
        //解析数据
        BasicModel *_model=[[BasicModel alloc]initWithResponse:responseObject];
        if ([_model.code isEqualToString:@"200"]) {
            NSDictionary *dataDict=responseObject[@"retContent"];
            _dateStr=[dataDict[@"serviceTime"] copy];
            
        }else if([_model.code isEqualToString:@"220"]){
            [LZXHelper postMessageWithText:_model.msg View:self.view];
        }
    } failure:^(NSError *error) {
        [LZXHelper hideLoadViewWithView:self.view];
    }];
}

#pragma mark -可签到mac地址请求

- (void)macAddressRequest{
    [LZXHelper postLoadViewWithText:HUD_PLEASEWAIT View:self.view];

    NSString* soap = [NSString stringWithFormat:@"<sessionId>%@</sessionId>\n<content></content>",[LZXHelper getSessionID]];
    // __weak AddressBookViewController *mySelf=self;
    [HttpRequest SOAPData:[LZXHelper getServerURL] SoapMthod:GetWifiMac soapBody:soap success:^(id responseObject) {
        [LZXHelper hideLoadViewWithView:self.view];
        
        //解析数据
        _macAddressModel=[[MacAddressModel alloc]initWithResponse:responseObject];
        if ([_macAddressModel.code isEqualToString:@"200"]) {
            //遍历数组如果找到可签到wifi则提示用户
            for (MacAddressModel *model in _macAddressModel.dataArr) {
                if ([model.wifiMac isEqualToString:[self getSSIDInfo]]) {
                    _isCompanyWifi=YES;
                    [LZXHelper postMessageWithText:[NSString stringWithFormat:@"已连接指定Wifi,可以%@!",_titleStr] View:[[UIApplication sharedApplication].delegate window]];
                    UIButton *subBtn=(UIButton *)[_scrollView viewWithTag:153];
                    subBtn.hidden=NO;
                    break;
                }
            }
            if (_isCompanyWifi) {
                NSString *cancelButtonTitle = NSLocalizedString(@"取消", nil);
                NSString *otherButtonTitle = NSLocalizedString(@"确定", nil);
                UIAlertController *alertController = [UIAlertController alertControllerWithTitle:[NSString stringWithFormat:@"确认要进行%@操作?",_titleStr] message:nil preferredStyle:UIAlertControllerStyleAlert];
                
                // Create the actions.
                UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:cancelButtonTitle style:UIAlertActionStyleCancel handler:^(UIAlertAction *action)
                                               {
                                                   //cancel Button
                                               }];
                UIAlertAction *otherAction = [UIAlertAction actionWithTitle:otherButtonTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction *action)
                                              {
                                                  [self postSignInOutInfoRequest:3];
                                              }];
                
                
                // Add the actions.
                [alertController addAction:otherAction];
                
                [alertController addAction:cancelAction];
                
                [self presentViewController:alertController animated:YES completion:nil];

            }
            
        }else if([_macAddressModel.code isEqualToString:@"220"]){
            [LZXHelper postMessageWithText:_macAddressModel.msg View:self.view];
        }
    } failure:^(NSError *error) {
        [LZXHelper hideLoadViewWithView:self.view];
    }];
}

#pragma mark -上传照片
- (void)uploadPhotoImage{
    //    if (!_image) {
    //        return;
    //    }
    //    [self.view addSubview:self.centerIndicator];
    //    [self.centerIndicator startAnimating];
    //    NSString *token=[[NSUserDefaults standardUserDefaults]objectForKey:@"Token"];
    //    NSIndexPath * selectedIndex = [_tableView indexPathForSelectedRow];
    //    MyInfoHeadViewCell * cell = [_tableView cellForRowAtIndexPath:selectedIndex];
    //    //NSString * sourcePath = [MyControl storeImagePath];
    //    PersonCenterViewController * pc = (PersonCenterViewController *)self.PersonVC;
    //
    
    NSMutableDictionary *picList=[NSMutableDictionary new];
    NSMutableArray *imageArr=[NSMutableArray new];
    
    for (int i=0; i<_photoArr.count; i++) {
        NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
        
        [formatter setDateFormat:@"yyyyMMddHHmmssSSS"];
        //以时间为照片命名
        NSString *timestamp = [[formatter stringFromDate:[NSDate date]] stringByAppendingString:@".jpg"];
        
        UIImage *image=_photoArr[i];
        NSData *date = UIImageJPEGRepresentation(image, 0.5);
        NSString * imageStr = [date base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
        NSDictionary *dict=@{
                             @"picName":timestamp,
                             @"picBase":imageStr,
                             @"picType":@"kq",
                             };
        
        [imageArr addObject:dict];
    }
    
    [picList setObject:imageArr forKey:@"picList"];
    //   字典转json
    NSData* jsonData = [NSJSONSerialization dataWithJSONObject:picList options:NSJSONWritingPrettyPrinted error:nil];
    NSString* str = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    //拼接soap字符串
    NSString* soap = [NSString stringWithFormat:@"<sessionId>%@</sessionId>\n<content>%@</content>",[LZXHelper getSessionID],str];
    
    [LZXHelper postLoadViewWithText:HUD_PLEASEWAIT View:self.view];
    
    [HttpRequest SOAPData:[LZXHelper getServerURL] SoapMthod:uploadPicInfo soapBody:soap success:^(id responseObject) {
        [LZXHelper hideLoadViewWithView:self.view];
        //解析数据并保存用户数据
        //NSLog(@"%@",responseObject[@"msg"]);
        _imageModel=[[UserHeadImageModel alloc]initWithResponse:responseObject];
        if ([_imageModel.code isEqualToString:@"200"]) {
            [self postPhotoSignInOutInfoRequest];
        }else if([_imageModel.code isEqualToString:@"220"]){
            [LZXHelper postMessageWithText:_imageModel.msg View:self.view];
        }
        
    } failure:^(NSError *error) {
        [LZXHelper hideLoadViewWithView:self.view];
    }];
    
}

#pragma mark -提交WIFI考勤信息
- (void)postSignInOutInfoRequest:(NSInteger)state{
    //    if (!_image) {
    //        return;
    //    }
    //    [self.view addSubview:self.centerIndicator];
    //    [self.centerIndicator startAnimating];
    //    NSString *token=[[NSUserDefaults standardUserDefaults]objectForKey:@"Token"];
    //    NSIndexPath * selectedIndex = [_tableView indexPathForSelectedRow];
    //    MyInfoHeadViewCell * cell = [_tableView cellForRowAtIndexPath:selectedIndex];
    //    //NSString * sourcePath = [MyControl storeImagePath];
    //    PersonCenterViewController * pc = (PersonCenterViewController *)self.PersonVC;
    //
    
//    NSMutableDictionary *picList=[NSMutableDictionary new];
//    NSMutableArray *imageArr=[NSMutableArray new];
//    
//    for (int i=0; i<_photoArr.count; i++) {
//        UIImage *image=_photoArr[i];
//        NSData *date = UIImageJPEGRepresentation(image, 0.5);
//        NSString * imageStr = [date base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
//        NSDictionary *dict=@{
//                             @"picName":@"headImage.jpg",
//                             @"picBase":imageStr,
//                             @"picType":@"kq",
//                             };
//        
//        [imageArr addObject:dict];
//    }
    NSString *latitude=@"";
    NSString *longitude=@"";
    if (_userLocation) {
        latitude=[NSString stringWithFormat:@"%f",_userLocation.location.coordinate.latitude];
        longitude=[NSString stringWithFormat:@"%f",_userLocation.location.coordinate.longitude];
    }
    //OutOfArea 0代表在范围内，1代表不再范围内
    NSDictionary *dict=@{
                         @"addressStr":_mapAddress?_mapAddress:@"",
                         @"elevation":@"33",
                         @"event_State":self.eventState?self.eventState:@"",
                         @"businessCode":@"",
                         @"OutOfArea":@"0",
                         @"kqType":@"5",
                         @"latitude":latitude,
                         @"longitude":longitude,
                         @"normalSignIn":@"1",
                         @"signClass":_signClass?_signClass:@"0",
                         @"signIntype":_signIntype,
                         @"signTimeSep":_signTimeSep?_signTimeSep:@"",
                         };
    
    
//    [picList setObject:imageArr forKey:@"picList"];
    //   字典转json
    NSData* jsonData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:nil];
    NSString* str = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    //拼接soap字符串
    NSString* soap = [NSString stringWithFormat:@"<sessionId>%@</sessionId>\n<content>%@</content>",[LZXHelper getSessionID],str];
    
    [LZXHelper postLoadViewWithText:HUD_PLEASEWAIT View:self.view];
    //{"OutOfArea":"0","addressStr":"陕西省西安市碑林区雁塔北路52号","businessCode":"","elevation":"33","event_State":"旷工","kqType":"5","latitude":"34.250195","longitude":"108.968778","normalSignIn":"1","signClass":"0","signIntype":"1","signTimeSep":"2016-11-25 08:30|2016-11-25 17:30","taskId":""}
    [HttpRequest SOAPData:[LZXHelper getServerURL] SoapMthod:postSignInOutInfo soapBody:soap success:^(id responseObject) {
        [LZXHelper hideLoadViewWithView:self.view];
        //解析数据并保存用户数据
        //NSLog(@"%@",responseObject[@"msg"]);
        //
        SignOutInfoModel *model=[[SignOutInfoModel alloc]initWithResponse:responseObject];
//        [LZXHelper postMessageWithText:model.msg View:[[UIApplication sharedApplication].delegate window]];
        if ([model.code isEqualToString:@"220"]) {
            //[LZXHelper postMessageWithText:model.msg View:self.view];
            [self updateCardRequestWithModel:model];
            [self noticeRequestWithMessage:model.msg];
        }else if([model.code isEqualToString:@"200"]){
            [LZXHelper postMessageWithText:model.msg View:self.view];
        }
        
    } failure:^(NSError *error) {
        [LZXHelper hideLoadViewWithView:self.view];
    }];
    
}


#pragma mark -提交拍照考勤信息
- (void)postPhotoSignInOutInfoRequest{
    
    //添加照片信息
    NSMutableArray *imageInfoArr=[NSMutableArray new];
    for (int i=0; i<_imageModel.dataArr.count; i++) {
        NSMutableDictionary *dict=[NSMutableDictionary new];
        UserHeadImageModel *model=_imageModel.dataArr[0];
        [dict setObject:model.picPath forKey:@"attendPicPath"];
        [dict setObject:model.picName forKey:@"attendPicName"];
        [imageInfoArr addObject:dict];
    }
    
    NSString *latitude=@"";
    NSString *longitude=@"";
    if (_userLocation) {
        latitude=[NSString stringWithFormat:@"%f",_userLocation.location.coordinate.latitude];
        longitude=[NSString stringWithFormat:@"%f",_userLocation.location.coordinate.longitude];
    }
    
    //OutOfArea 0代表在范围内，1代表不再范围内
    NSDictionary *dict=@{
                         @"addressStr":_mapAddress?_mapAddress:@"",
                         @"elevation":@"33",
                         @"event_State":self.eventState?self.eventState:@"",
                         @"businessCode":@"",
                         @"OutOfArea":self.outOfArea?self.outOfArea:@"1",
                         @"kqType":@"0",// 0：拍照考勤1：NFC考勤2：二维码考勤3：指纹考勤4：人脸识别考勤5：WIFI考勤6：其他考勤
                         @"latitude":latitude,
                         @"longitude":longitude,
                         @"normalSignIn":@"1",
                         @"signClass":_signClass?_signClass:@"0",
                         @"signIntype":_signIntype,
                         @"signTimeSep":_signTimeSep?_signTimeSep:@"",
                         @"isPressed":self.isPressed?self.isPressed:@"",
                         @"attendPhotoList":imageInfoArr
                         };
    
    
    //    [picList setObject:imageArr forKey:@"picList"];
    //   字典转json
    NSData* jsonData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:nil];
    NSString* str = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    //拼接soap字符串
    NSString* soap = [NSString stringWithFormat:@"<sessionId>%@</sessionId>\n<content>%@</content>",[LZXHelper getSessionID],str];
    
    [LZXHelper postLoadViewWithText:HUD_PLEASEWAIT View:self.view];
    
    [HttpRequest SOAPData:[LZXHelper getServerURL] SoapMthod:postSignInOutInfo soapBody:soap success:^(id responseObject) {
        [LZXHelper hideLoadViewWithView:self.view];
        //解析数据并保存用户数据
        //NSLog(@"%@",responseObject[@"msg"]);
        SignOutInfoModel *model=[[SignOutInfoModel alloc]initWithResponse:responseObject];
        if ([model.code isEqualToString:@"220"]) {
            [self updateCardRequestWithModel:model];
            [self noticeRequestWithMessage:model.msg];
        }else if([model.code isEqualToString:@"200"]){
            NSLog(@"%@",responseObject);
            [LZXHelper postMessageWithText:model.msg View:self.view];
        }
        
    } failure:^(NSError *error) {
        [LZXHelper hideLoadViewWithView:self.view];
    }];
    
}

#pragma mark -更新用户数据

- (void)updateCardRequestWithModel:(SignOutInfoModel *)model{

    NSDictionary *dict=@{
                         @"businessCode":model.businessCode?model.businessCode:@"",
                         @"pk":model.pk?model.pk:@"",
                         @"taskId":model.taskId?model.taskId:@""
                         };
    
    //   字典转json
    NSData* jsonData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:nil];
    NSString* str = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    //拼接soap字符串
    NSString* soap = [NSString stringWithFormat:@"<sessionId>%@</sessionId>\n<content>%@</content>",[LZXHelper getSessionID],str];
    //[LZXHelper postLoadViewWithText:HUD_PLEASEWAIT View:self.view];
    [HttpRequest SOAPData:[LZXHelper getServerURL] SoapMthod:UpdateCardInfo soapBody:soap success:^(id responseObject) {
        //[LZXHelper hideLoadViewWithView:self.view];
        
        //解析数据
        BasicModel *model=[[BasicModel alloc]initWithResponse:responseObject];
        if ([model.code isEqualToString:@"200"]) {

            //[LZXHelper postMessageWithText:model.msg View:self.view];
           // [self backClick];
        }else if([model.code isEqualToString:@"220"]){
            [LZXHelper postMessageWithText:model.msg View:self.view];
        }
    } failure:^(NSError *error) {
        //[LZXHelper hideLoadViewWithView:self.view];
    }];
}

#pragma mark -考勤记录请求

- (void)noticeRequestWithMessage:(NSString *)msg{
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    
    [formatter setDateFormat:@"yyyy-MM"];
    //以时间为照片命名
    NSString *timestamp = [formatter stringFromDate:[NSDate date]];
    
    NSDictionary *dict=@{
//                         @"beginMonthDate":timestamp,
//                         @"conditionWord":@"",
//                         @"departList":@[],
//                         @"endMonthDate":timestamp,
//                         @"fid":@"",
//                         @"khitemList":@[],
//                         @"postList":@[],
//                         @"state":@"0",
//                         @"type":@"1"
                           @"strDate":timestamp
                         };
    
    //   字典转json
    NSData* jsonData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:nil];
    NSString* str = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    //拼接soap字符串
    NSString* soap = [NSString stringWithFormat:@"<sessionId>%@</sessionId>\n<content>%@</content>",[LZXHelper getSessionID],str];
    //[LZXHelper postLoadViewWithText:HUD_PLEASEWAIT View:self.view];
    [HttpRequest SOAPData:[LZXHelper getServerURL] SoapMthod:getMonthAttendanceList soapBody:soap success:^(id responseObject) {
        //[LZXHelper hideLoadViewWithView:self.view];
        
        //解析数据
        SignInNoticeModel *model=[[SignInNoticeModel alloc]initWithResponse:responseObject];
        if ([model.code isEqualToString:@"200"]) {
            //[LZXHelper postMessageWithText:model.msg View:self.view];
            [self creatNoticeViewWithModel:model message:msg];
        }else if([model.code isEqualToString:@"220"]){
            //[LZXHelper postMessageWithText:model.msg View:self.view];
        }
    } failure:^(NSError *error) {
        //[LZXHelper hideLoadViewWithView:self.view];
    }];
}


#pragma mark -获取百度地图可签到位置区域

- (void)getSigninLocationListRequest{
    
    NSDictionary *dict=@{
                         };
    
    //   字典转json
    NSData* jsonData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:nil];
    NSString* str = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    //拼接soap字符串
    NSString* soap = [NSString stringWithFormat:@"<sessionId>%@</sessionId>\n<content>%@</content>",[LZXHelper getSessionID],str];
    //[LZXHelper postLoadViewWithText:HUD_PLEASEWAIT View:self.view];
    [HttpRequest SOAPData:[LZXHelper getServerURL] SoapMthod:getSigninLocationList soapBody:soap success:^(id responseObject) {
        //[LZXHelper hideLoadViewWithView:self.view];
        
        //解析数据
        _locationModel=[[LocationListModel alloc]initWithResponse:responseObject];
        if ([_locationModel.code isEqualToString:@"200"]) {
            //[LZXHelper postMessageWithText:model.msg View:self.view];
            [self setOutOfAreaWithListModel];

        }else if([_locationModel.code isEqualToString:@"220"]){
            //[LZXHelper postMessageWithText:model.msg View:self.view];
        }
    } failure:^(NSError *error) {
        //[LZXHelper hideLoadViewWithView:self.view];
    }];
}

- (void)dealloc{

}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
